package team.epos.merchant.servlet;

import team.epos.merchant.dto.ResponseBody;
import team.epos.merchant.service.BaseInfoServiceImpl;
import team.epos.utils.annotation.RequestMethod;
import team.epos.utils.pojo.Dishes;
import team.epos.utils.pojo.Store;
import team.epos.utils.servlet.BaseServlet;
import team.epos.utils.util.JsonUtil;
import team.epos.utils.util.PojoParamUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author CHENKI
 */
public class BaseInfoServlet extends BaseServlet {
    private BaseInfoServiceImpl baseInfoService = new BaseInfoServiceImpl();

    @RequestMethod(method = "findBaseInfo")
    public void findBaseInfo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sId = req.getParameter("sId");
        Store store = baseInfoService.findBaseInfo(Integer.valueOf(sId).intValue());
        String json=JsonUtil.obJectToJson(store);
        resp.getWriter().write(json);
//        req.setAttribute("baseInfo", store);
//        req.getRequestDispatcher("/jsp/baseInfo.html").forward(req, resp);
    }

    @RequestMethod(method = "updateBaseInfo")
    public void updateBaseInfo(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Store store = PojoParamUtil.getObject(req, Store.class);
        int i = 0;
        i = baseInfoService.updateBaseInfo(store);
//        if (i > 0) {
//            resp.sendRedirect("/baseInfo?method=findBaseInfo&sId=" + store.getId());
//        } else {
            resp.getWriter().write(String.valueOf(i));
//        }

    }
}
